/*
 * MobilePortScannerMIDlet.java
 *
 * Created on 25 febbraio 2004, 17.14
 */

import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.*;


/**
 * An example MIDlet with simple "Hello" text and an Exit command.
 * Refer to the startApp, pauseApp, and destroyApp
 * methods so see how each handles the requested transition.
 *
 * @author  klimt
 * @version
 */
public class MobilePortScannerMIDlet extends MIDlet implements CommandListener {
    
    private Command exitCommand; // The exit command
    private Display display;    // The display for this MIDlet
    private Command scanCommand;
    private TextField txtHost;
    private PortScan scan;
    private Ticker tkStatus;
    
    public Form form_main;
    private StringItem si;
    //private SocketConnection sc;
    private InputStream is;
    //private String remoteTimeServerAddress;

    
    
    public MobilePortScannerMIDlet() {
        display = Display.getDisplay(this);
        exitCommand = new Command("Exit", Command.EXIT, 2);
        scanCommand = new Command("Scan", Command.BACK,2);
        tkStatus = new Ticker("MobilePortScanner...insert hostname...");
        txtHost = new TextField("HostName:", "127.0.0.1", 30, TextField.ANY);
        
    }
    
    /**
     * Start up the Hello MIDlet by creating the TextBox and associating
     * the exit command and listener.
     */
    public void startApp() {
        
        
        
        
        form_main = new Form("MobilePortScanner");
        form_main.setTicker(tkStatus);
        form_main.addCommand(exitCommand);
        form_main.addCommand(scanCommand);
        form_main.append(txtHost);
        form_main.append("\nMobilePortScanner\nBy Andrea 'Kl1mT' Fortuna\nhttp://www.ariellab.org\nklimt@ariellab.org");
        form_main.setCommandListener(this);
        
        display.setCurrent(form_main);
    }
    
    /**
     * Pause is a no-op since there are no background activities or
     * record stores that need to be closed.
     */
    public void pauseApp() {
    }
    
    /**
     * Destroy must cleanup everything not handled by the garbage collector.
     * In this case there is nothing to cleanup.
     */
    public void destroyApp(boolean unconditional) {
    }
    
   
    
    
    
    /*
     * Respond to commands, including exit
     * On the exit command, cleanup and notify that the MIDlet has been destroyed.
     */
    public void commandAction(Command c, Displayable s) {
        if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        } else if (c==scanCommand) {
           scan = new PortScan(this,txtHost.getString());
           scan.start();
           //display.setCurrent(form_main);
        }
    }
    
}
